import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public class DbPoolUtil
{

    static final Logger logger = LoggerFactory.getLogger(DbPoolUtil.class);
    public static boolean inited;
    private static DataSource dataSource;

    public static boolean isInited()
    {
        return inited;
    }

    public static void setInited(boolean inited)
    {
        DbPoolUtil.inited = inited;
    }

    public static Connection getConnection() throws SQLException
    {
        if (!inited)
        {
            throw new SQLException("DbPoolUtil.NotInited");
        }
        return dataSource.getConnection();
    }

    public void setDataSource(DataSource dataSource)
    {
        this.dataSource = dataSource;
        setInited(true);
    }


}
